require "go.ui.Scene"
require "gravityProtocol"

require "UserBall"
require "BallFactory"

class 'gravityScene' (Scene)

function gravityScene:__init(id)	super(id)
	self:SetupUIObjects()

	self.p1 = BallFactory:CreateBall("generic", "P1")
	print (self.p1:tostring())
	--self.player = PlayerObject("player")
	--self.player.Show(true)
	--self:SetMsgHandler(Evt_KeyboardDown, self.OnKeyDown)
end

function gravityScene:OnKeyDown(msg)
	--local keyValue = msg:GetNValue(Evt_KeyboardDown.key.Value)
	--print(keyValue)
end

function gravityScene:Update(elapsed)
	if gameapp:GetSelfPlayer() == nil then
		return
	end

	-- check keyboard state
	local dir = Vector2(0, 0)
	local pressedL, optL = self:GetKeyPressed(UIConst.KeyLeft)
	local pressedU, optU = self:GetKeyPressed(UIConst.KeyUp)
	local pressedR, optR = self:GetKeyPressed(UIConst.KeyRight)
	local pressedD, optD = self:GetKeyPressed(UIConst.KeyDown)

	if pressedU then dir.y = dir.y-1 end
	if pressedD then dir.y = dir.y+1 end
end

require "gravitySceneUIObject"